#pragma once
#include "afn0dbase.h"

#pragma pack(1)
class ActiveAfn0df5 : public Afn0dfbase
{
public:
	CommonA20 _time;
public:
	inline ActiveAfn0df5(uint16_t pn = 0)
	:Afn0dfbase(5, pn)
	{
	}
	inline uint16_t length(void)const
	{
		return sizeof(*this);
	}
	inline Mapss& get(Mapmss& mss)const
	{
		Mapss& m = mss[(int)pnfn];
		m["Fn"]   = Fn();
		m["Pn"]   = Pn();
		m["_time"] = _time.toStringU();
		return m;
	}
	inline bool set(const Mapss& m)
	{
		if(!m.have("Pn")
		|| !m.have("_time")
		|| !m.equal("Fn", Fn()))
		{
			return false;
		}
		int pn = 0;
		Mapss M = m;
		Pn(M["Pn"].toint());
		M["_time"] >> _time;
		return true;
	}
};

class PasiveAfn0df5 : public Afn0dfbase
{
public:
	enum{RATE_MIN = 1, RATE_MAX = 12};
public:
	Td_d frozTime;
	Td_c copyTime;
	uint8_t _rate;
	CommonA23 _rsvttamd;			//reverseTotalActiveMaxDemand;
	CommonA23 _rsvamd[RATE_MAX];	//reverseActiveMaxDemand[RATE_MAX];
	CommonA17 _rsvttamdt;			//reverseTotalActiveMaxDemandTime;
	CommonA17 _rsvamdt[RATE_MAX];	//reverseActiveMaxDemandTime[RATE_MAX];
	CommonA23 _rsvttrmd;			//reverseTotalReactiveMaxDemand;
	CommonA23 _rsvrmd[RATE_MAX];	//reverseReactiveMaxDemand[RATE_MAX];
	CommonA17 _rsvttrmdt;			//reverseTotalReactiveMaxDemandTime;
	CommonA17 _rsvrmdt[RATE_MAX];	//reverseReactiveMaxDemandTime[RATE_MAX];
public:
	PasiveAfn0df5(uint16_t pn = 0)
	:Afn0dfbase(5, pn),_rate(RATE_MAX)
	{
	}
	inline Mapss& get(Mapmss& mss)const
	{
		Mapss& m = mss[(int)pnfn];
		return m;
	}
	inline uint16_t length(void)const
	{
		if(_rate >= RATE_MIN && _rate <= RATE_MAX)
		{
			return sizeof(PasiveAfn0df5)
				 - (RATE_MAX - _rate) * sizeof(CommonA23)
				 - (RATE_MAX - _rate) * sizeof(CommonA17)
				 - (RATE_MAX - _rate) * sizeof(CommonA23)
				 - (RATE_MAX - _rate) * sizeof(CommonA17)
				 ;
		}
	}
	inline void rate(uint8_t r)
	{
		if(r >= RATE_MIN && r <= RATE_MAX)
		{
			_rate = r;
		}
	}
};
#pragma pack(0)
